'use strict';

// const Controller = require('egg').Controller;
const BaseController = require('../core/base_controller');

class PersonController extends BaseController {
  async index() {
    console.log("home")
    // await ctx.service.UploadService()
    // this.ctx.body = 'hi, egg';
  }


  async sendMessage() {//pc发给个人
    const {
      ctx
    } = this;
    const params = ctx.request.body;
    // console.log("home")
    await ctx.model.PersonMessage.create({
      userId: params.id,
      content: params.content,
    })
    this.success({}, "创建消息成功");
  }


  async getMessage() {   
    const {
      ctx
    } = this;
    // const params = ctx.request.body;
    const query = this.ctx.query;
    //  console.log("---------",ctx.header.token)
   const list =  await ctx.model.PersonMessage.findAll({
       where:{
      userId: Number(query.id),      
       }
    })
    this.success({list:list}, "ok");
    
  }
  async deleteMessage() {
    const {
      ctx
    } = this;
    const params = ctx.request.body;
    // console.log("home")
    await ctx.model.PersonMessage.create({
      userId: params.id,
      content: params.content,
    })

    this.success({},'删除成功')
  }
  
 async kfGetMSG(){
    const {
      ctx
    } = this;
    const msg= await ctx.model.KfMessage.findAll();
    this.success({list:msg},'成功')
  }

async userSendMSG(){
  const {
    ctx
  } = this;
  const p = ctx.request.body;//ID MSG
  await ctx.model.KfMessage.create({userId:p.userId,msg:p.msg})
    
}
async kfSendMSG(){
  const {
    ctx
  } = this;
  const p = ctx.request.body;//ID MSG
  await ctx.model.KfMessage.create({userId:p.userId,msg:p.msg})
    
}

}


module.exports = PersonController;